package cn.tedu.csms.shop.controller;

import cn.tedu.csms.base.response.JsonResult;
import cn.tedu.csms.shop.pojo.dto.ShopLoginDto;
import cn.tedu.csms.shop.pojo.dto.ShopQuery;
import cn.tedu.csms.shop.pojo.dto.ShopSaveParam;
import cn.tedu.csms.shop.pojo.vo.ShopVO;
import cn.tedu.csms.shop.service.ShopService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "店铺管理模块")
@Slf4j
@RestController
@RequestMapping("/v1/shop")
public class ShopController {
    @Autowired
    private ShopService shopService;

    @GetMapping("login")
    @ApiOperation(value = "用户登录")
    public JsonResult login(ShopLoginDto shopLoginDto) {
        log.debug("用户登录，参数={}", shopLoginDto);
        ShopVO shopVO = shopService.shopLogin(shopLoginDto);
        return JsonResult.ok(shopVO);
    }

    @GetMapping("select")
    @ApiOperation(value = "查询店铺数据")
    public JsonResult selectShop(ShopQuery shopQuery) {
        log.debug("查询店铺数据,参数:{}",shopQuery);
        List<ShopVO> list = shopService.selectShops(shopQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("update")
    @ApiOperation(value = "更新店铺数据")
    public JsonResult updateShop(@RequestBody ShopSaveParam shopSaveParam) {
        log.debug("更新店铺数据，参数：{}", shopSaveParam);
        shopService.updateShop(shopSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("add")
    @ApiOperation(value = "新增店铺数据")
    public JsonResult addShop(@RequestBody ShopSaveParam shopSaveParam) {
        log.debug("新增店铺数据，参数：{}", shopSaveParam);
        shopService.addShop(shopSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除店铺数据")
    public JsonResult deleteShop(@PathVariable("id") Long id) {
        log.debug("删除店铺数据，ID：{}", id);
        shopService.deleteShop(id);
        return JsonResult.ok();
    }

    @PostMapping("updateStatus/{id}/{status}")
    @ApiOperation(value = "更新店铺状态")
    public JsonResult updateStatus(@PathVariable("id") Long id, @PathVariable("status") String status) {
        log.debug("更新店铺状态，ID：{}，状态：{}", id, status);
        shopService.updateStatus(id, status);
        return JsonResult.ok();
    }

}
